package com.company.笔试.出现1的次数;

/**
 * @Classname NewSolution
 * @Description TODO
 * @Date 2021/8/15 21:43
 * @Created by ylr
 */
public class NewSolution {
    public static void main(String[] args) {

    }
    public int NumberOf1Between1AndN_Solution(int n) {
        // write code here
        int counts,num;
        counts = 0;
        if(n < 1){
            return 0;
        }
        for(int i = 1;i <= n;i++){
            num = i;
            //num = num%10;
            while(num > 0){
                if(num%10 == 1){
                    counts++;
                }
                num = (int)Math.floor(num/10.0);
            }
        }
        return counts;
    }
}
